package com.lou1052.redis.jedis.factorybean.share;

import com.lou1052.core.base.annotation.thread.ThreadSafe;
import com.lou1052.core.serializer.Serializer;
import com.lou1052.redis.jedis.ext.client.shard.ShardedJedisExt;
import com.lou1052.redis.jedis.factorybean.AbsJedisCommandsFactory;
import com.lou1052.redis.jedis.source.share.ShardedJedisExtSource;
import com.lou1052.redis.jedis.source.share.ShardedJedisSource;
import redis.clients.jedis.*;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;

/**
 * Created with IntelliJ IDEA.
 * User: liuqing
 * Date: 2015/10/14
 * Time: 22:00
 * To change this template use File | Settings | File Templates.
 */
@ThreadSafe
public class ShardedJedisExtFactory extends AbsJedisCommandsFactory<ShardedJedisExt,ShardedJedisExtSource> {

    public ShardedJedisExtFactory(ShardedJedisExtSource source) {
        super(source);
    }


    @Override
    public ShardedJedisExt getObject() throws Exception {
        return saftJedis;
    }


    private final SafeJedis saftJedis = new SafeJedis();

    private class SafeJedis extends ShardedJedisExt {

        @Override
        public Long append(String key, String value) {
            ShardedJedis jedis = source.getSource();
            try {
                return jedis.append(key, value);
            }finally {
                jedis.close();
            }
        }

        @Override
        public Long bitcount(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.bitcount(key);
            }

        }

        @Override
        public Long bitcount(String key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.bitcount(key, start, end);
            }
        }

        @Override
        public List<String> blpop(String arg) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.blpop(arg);
            }
        }

        @Override
        public List<String> blpop(int timeout, String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.blpop(timeout, key);
            }
        }

        @Override
        public List<String> brpop(String arg) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.brpop(arg);
            }
        }

        @Override
        public List<String> brpop(int timeout, String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.brpop(timeout, key);
            }
        }

        @Override
        public void close() {
            //
        }

        @Override
        public Long decr(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.decr(key);
            }
        }

        @Override
        public Long decrBy(String key, long integer) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.decrBy(key, integer);
            }
        }

        @Override
        public Long del(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.del(key);
            }
        }

        @Override
        public String echo(String string) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.echo(string);
            }
        }

        @Override
        public Boolean exists(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.exists(key);
            }
        }

        @Override
        public Long expire(String key, int seconds) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.expire(key, seconds);
            }
        }

        @Override
        public Long expireAt(String key, long unixTime) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.expireAt(key, unixTime);
            }
        }

        @Override
        public String get(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.get(key);
            }
        }

        @Override
        public Boolean getbit(String key, long offset) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.getbit(key, offset);
            }
        }

        @Override
        public String getrange(String key, long startOffset, long endOffset) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.getrange(key, startOffset, endOffset);
            }
        }

        @Override
        public Serializer getSerializer(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.getSerializer(key);
            }
        }

        @Override
        public String getSet(String key, String value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.getSet(key, value);
            }
        }

        @Override
        public Long hdel(String key, String... fields) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hdel(key, fields);
            }
        }

        @Override
        public Boolean hexists(String key, String field) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hexists(key, field);
            }
        }

        @Override
        public String hget(String key, String field) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hget(key, field);
            }
        }

        @Override
        public Map<String, String> hgetAll(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hgetAll(key);
            }
        }

        @Override
        public Long hincrBy(String key, String field, long value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hincrBy(key, field, value);
            }
        }

        @Override
        public Double hincrByFloat(String key, String field, double value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hincrByFloat(key, field, value);
            }
        }

        @Override
        public Set<String> hkeys(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hkeys(key);
            }
        }

        @Override
        public Long hlen(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hlen(key);
            }
        }

        @Override
        public List<String> hmget(String key, String... fields) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hmget(key, fields);
            }
        }

        @Override
        public String hmset(String key, Map<String, String> hash) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hmset(key, hash);
            }
        }

        @Override
        public ScanResult<Map.Entry<String, String>> hscan(String key, int cursor) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hscan(key, cursor);
            }
        }


        @Override
        public ScanResult<Map.Entry<String, String>> hscan(String key, String cursor) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hscan(key, cursor);
            }
        }

        @Override
        public Long hset(String key, String field, String value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hset(key, field, value);
            }
        }

        @Override
        public Long hsetnx(String key, String field, String value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hsetnx(key, field, value);
            }
        }

        @Override
        public List<String> hvals(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hvals(key);
            }
        }

        @Override
        public Long incr(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.incr(key);
            }
        }

        @Override
        public Long incrBy(String key, long integer) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.incrBy(key, integer);
            }
        }

        @Override
        public Double incrByFloat(String key, double value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.incrByFloat(key, value);
            }
        }

        @Override
        public String lindex(String key, long index) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.lindex(key, index);
            }
        }

        @Override
        public Long linsert(String key, BinaryClient.LIST_POSITION where, String pivot, String value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.linsert(key, where, pivot, value);
            }
        }

        @Override
        public Long llen(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.llen(key);
            }
        }

        @Override
        public String lpop(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.lpop(key);
            }
        }

        @Override
        public Long lpush(String key, String... strings) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.lpush(key, strings);
            }
        }

        @Override
        public Long lpushx(String key, String... string) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.lpushx(key, string);
            }
        }

        @Override
        public List<String> lrange(String key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.lrange(key, start, end);
            }
        }

        @Override
        public Long lrem(String key, long count, String value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.lrem(key, count, value);
            }
        }

        @Override
        public String lset(String key, long index, String value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.lset(key, index, value);
            }
        }

        @Override
        public String ltrim(String key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.ltrim(key, start, end);
            }
        }


        @Override
        public Long move(String key, int dbIndex) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.move(key, dbIndex);
            }
        }



        @Override
        public Long persist(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.persist(key);
            }
        }

        @Override
        public Long pexpire(String key, long milliseconds) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.pexpire(key, milliseconds);
            }
        }

        @Override
        public Long pexpireAt(String key, long millisecondsTimestamp) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.pexpireAt(key, millisecondsTimestamp);
            }
        }

        @Override
        public Long pfadd(String key, String... elements) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.pfadd(key, elements);
            }
        }

        @Override
        public long pfcount(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.pfcount(key);
            }
        }

        @Override
        public String rpop(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.rpop(key);
            }
        }

        @Override
        public Long rpush(String key, String... strings) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.rpush(key, strings);
            }
        }

        @Override
        public Long rpushx(String key, String... string) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.rpushx(key, string);
            }
        }

        @Override
        public Long sadd(String key, String... members) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.sadd(key, members);
            }
        }




        @Override
        public Long scard(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.scard(key);
            }
        }






        @Override
        public String set(String key, String value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.set(key, value);
            }}

        @Override
        public String set(String key, String value, String nxxx, String expx, long time) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.set(key, value, nxxx, expx, time);
            }}

        @Override
        public Boolean setbit(String key, long offset, boolean value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.setbit(key, offset, value);
            }}

        @Override
        public Boolean setbit(String key, long offset, String value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.setbit(key, offset, value);
            }}


        @Override
        public String setex(String key, int seconds, String value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.setex(key, seconds, value);
            }}

        @Override
        public Long setnx(String key, String value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.setnx(key, value);
            }}

        @Override
        public Long setrange(String key, long offset, String value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.setrange(key, offset, value);
            }}

        @Override
        public void setSerializerFunction(Function<String, Serializer> serializerFunction) {
            try(ShardedJedis jedis = source.getSource()) {
                jedis.setSerializerFunction(serializerFunction);
            }}

        @Override
        public Boolean sismember(String key, String member) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.sismember(key, member);
            }}



        @Override
        public Set<String> smembers(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.smembers(key);
            }}

        @Override
        public List<String> sort(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.sort(key);
            }}


        @Override
        public List<String> sort(String key, SortingParams sortingParameters) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.sort(key, sortingParameters);
            }}


        @Override
        public String spop(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.spop(key);
            }}

        @Override
        public Set<String> spop(String key, long count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.spop(key, count);
            }}

        @Override
        public String srandmember(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.srandmember(key);
            }}

        @Override
        public List<String> srandmember(String key, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.srandmember(key, count);
            }}

        @Override
        public Long srem(String key, String... members) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.srem(key, members);
            }}

        @Override
        public ScanResult<String> sscan(String key, int cursor) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.sscan(key, cursor);
            }
        }

        @Override
        public ScanResult<String> sscan(String key, String cursor) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.sscan(key, cursor);
            }}

        @Override
        public Long strlen(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.strlen(key);
            }}


        @Override
        public String substr(String key, int start, int end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.substr(key, start, end);
            }}

        @Override
        public Long ttl(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.ttl(key);
            }}

        @Override
        public String type(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.type(key);
            }}

        @Override
        public Long zadd(String key, double score, String member) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zadd(key, score, member);
            }}

        @Override
        public Long zadd(String key, Map<String, Double> scoreMembers) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zadd(key, scoreMembers);
            }}

        @Override
        public Long zcard(String key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zcard(key);
            }}

        @Override
        public Long zcount(String key, double min, double max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zcount(key, min, max);
            }}

        @Override
        public Long zcount(String key, String min, String max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zcount(key, min, max);
            }}

        @Override
        public Double zincrby(String key, double score, String member) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zincrby(key, score, member);
            }}

        @Override
        public Long zlexcount(String key, String min, String max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zlexcount(key, min, max);
            }}

        @Override
        public Set<String> zrange(String key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrange(key, start, end);
            }}

        @Override
        public Set<String> zrangeByLex(String key, String min, String max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByLex(key, min, max);
            }}

        @Override
        public Set<String> zrangeByLex(String key, String min, String max, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByLex(key, min, max, offset, count);
            }}

        @Override
        public Set<String> zrangeByScore(String key, double min, double max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScore(key, min, max);
            }}

        @Override
        public Set<String> zrangeByScore(String key, double min, double max, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScore(key, min, max, offset, count);
            }}

        @Override
        public Set<String> zrangeByScore(String key, String min, String max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScore(key, min, max);
            }}

        @Override
        public Set<String> zrangeByScore(String key, String min, String max, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScore(key, min, max, offset, count);
            }}

        @Override
        public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScoreWithScores(key, min, max);
            }}

        @Override
        public Set<Tuple> zrangeByScoreWithScores(String key, double min, double max, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScoreWithScores(key, min, max, offset, count);
            }}

        @Override
        public Set<Tuple> zrangeByScoreWithScores(String key, String min, String max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScoreWithScores(key, min, max);
            }
        }

        @Override
        public Set<Tuple> zrangeByScoreWithScores(String key, String min, String max, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScoreWithScores(key, min, max, offset, count);
            }
        }

        @Override
        public Set<Tuple> zrangeWithScores(String key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeWithScores(key, start, end);
            }
        }

        @Override
        public Long zrank(String key, String member) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrank(key, member);
            }
        }

        @Override
        public Long zrem(String key, String... members) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrem(key, members);
            }
        }

        @Override
        public Long zremrangeByLex(String key, String min, String max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zremrangeByLex(key, min, max);
            }
        }

        @Override
        public Long zremrangeByRank(String key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zremrangeByRank(key, start, end);
            }
        }

        @Override
        public Long zremrangeByScore(String key, double start, double end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zremrangeByScore(key, start, end);
            }
        }

        @Override
        public Long zremrangeByScore(String key, String start, String end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zremrangeByScore(key, start, end);
            }
        }

        @Override
        public Set<String> zrevrange(String key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrange(key, start, end);
            }
        }

        @Override
        public Set<String> zrevrangeByLex(String key, String max, String min) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByLex(key, max, min);
            }
        }

        @Override
        public Set<String> zrevrangeByLex(String key, String max, String min, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByLex(key, max, min, offset, count);
            }
        }

        @Override
        public Set<String> zrevrangeByScore(String key, double max, double min) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScore(key, max, min);
            }
        }

        @Override
        public Set<String> zrevrangeByScore(String key, double max, double min, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScore(key, max, min, offset, count);
            }
        }

        @Override
        public Set<String> zrevrangeByScore(String key, String max, String min) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScore(key, max, min);
            }
        }

        @Override
        public Set<String> zrevrangeByScore(String key, String max, String min, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScore(key, max, min, offset, count);
            }
        }

        @Override
        public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScoreWithScores(key, max, min);
            }
        }

        @Override
        public Set<Tuple> zrevrangeByScoreWithScores(String key, double max, double min, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScoreWithScores(key, max, min, offset, count);
            }
        }

        @Override
        public Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScoreWithScores(key, max, min);
            }
        }

        @Override
        public Set<Tuple> zrevrangeByScoreWithScores(String key, String max, String min, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScoreWithScores(key, max, min, offset, count);
            }
        }

        @Override
        public Set<Tuple> zrevrangeWithScores(String key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeWithScores(key, start, end);
            }
        }

        @Override
        public Long zrevrank(String key, String member) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrank(key, member);
            }
        }

        @Override
        public ScanResult<Tuple> zscan(String key, int cursor) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zscan(key, cursor);
            }
        }


        @Override
        public ScanResult<Tuple> zscan(String key, String cursor) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zscan(key, cursor);
            }
        }

        @Override
        public Double zscore(String key, String member) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zscore(key, member);
            }
        }


        @Override
        public Long append(byte[] key, byte[] value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.append(key, value);
            }
        }



        @Override
        public Long bitcount(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.bitcount(key);
            }
        }

        @Override
        public Long bitcount(byte[] key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.bitcount(key, start, end);
            }
        }

        @Override
        public List<byte[]> blpop(byte[] arg) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.blpop(arg);
            }
        }



        @Override
        public List<byte[]> brpop(byte[] arg) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.brpop(arg);
            }
        }


        @Override
        public Long decr(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.decr(key);
            }
        }

        @Override
        public Long decrBy(byte[] key, long integer) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.decrBy(key, integer);
            }
        }

        @Override
        public Long del(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.del(key);
            }
        }

        @Override
        public void disconnect() {
            try(ShardedJedis jedis = source.getSource()) {
                jedis.disconnect();
            }
        }


        @Override
        public byte[] echo(byte[] string) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.echo(string);
            }
        }

        @Override
        public Boolean exists(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.exists(key);
            }
        }

        @Override
        public Long expire(byte[] key, int seconds) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.expire(key, seconds);
            }
        }

        @Override
        public Long expireAt(byte[] key, long unixTime) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.expireAt(key, unixTime);
            }
        }

        @Override
        public byte[] get(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.get(key);
            }
        }

        @Override
        public Boolean getbit(byte[] key, long offset) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.getbit(key, offset);
            }
        }
        
        @Override
        public byte[] getrange(byte[] key, long startOffset, long endOffset) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.getrange(key, startOffset, endOffset);
            }
        }

        @Override
        public byte[] getSet(byte[] key, byte[] value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.getSet(key, value);
            }
        }

        @Override
        public Long hdel(byte[] key, byte[]... fields) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hdel(key, fields);
            }
        }

        @Override
        public Boolean hexists(byte[] key, byte[] field) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hexists(key, field);
            }
        }

        @Override
        public byte[] hget(byte[] key, byte[] field) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hget(key, field);
            }
        }

        @Override
        public Map<byte[], byte[]> hgetAll(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hgetAll(key);
            }
        }

        @Override
        public Long hincrBy(byte[] key, byte[] field, long value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hincrBy(key, field, value);
            }
        }

        @Override
        public Double hincrByFloat(byte[] key, byte[] field, double value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hincrByFloat(key, field, value);
            }
        }

        @Override
        public Set<byte[]> hkeys(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hkeys(key);
            }
        }

        @Override
        public Long hlen(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hlen(key);
            }
        }

        @Override
        public List<byte[]> hmget(byte[] key, byte[]... fields) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hmget(key, fields);
            }
        }

        @Override
        public String hmset(byte[] key, Map<byte[], byte[]> hash) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hmset(key, hash);
            }
        }

        @Override
        public Long hset(byte[] key, byte[] field, byte[] value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hset(key, field, value);
            }
        }

        @Override
        public Long hsetnx(byte[] key, byte[] field, byte[] value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.hsetnx(key, field, value);
            }
        }

        @Override
        public Long incr(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.incr(key);
            }
        }

        @Override
        public Long incrBy(byte[] key, long integer) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.incrBy(key, integer);
            }
        }

        @Override
        public Double incrByFloat(byte[] key, double integer) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.incrByFloat(key, integer);
            }
        }

        @Override
        public byte[] lindex(byte[] key, long index) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.lindex(key, index);
            }
        }

        @Override
        public Long linsert(byte[] key, BinaryClient.LIST_POSITION where, byte[] pivot, byte[] value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.linsert(key, where, pivot, value);
            }}

        @Override
        public Long llen(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.llen(key);
            }
        }

        @Override
        public byte[] lpop(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.lpop(key);
            }
        }

        @Override
        public Long lpush(byte[] key, byte[]... strings) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.lpush(key, strings);
            }
        }

        @Override
        public Long lpushx(byte[] key, byte[]... string) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.lpushx(key, string);
            }
        }

        @Override
        public List<byte[]> lrange(byte[] key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.lrange(key, start, end);
            }
        }

        @Override
        public Long lrem(byte[] key, long count, byte[] value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.lrem(key, count, value);
            }
        }

        @Override
        public String lset(byte[] key, long index, byte[] value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.lset(key, index, value);
            }
        }

        @Override
        public String ltrim(byte[] key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.ltrim(key, start, end);
            }
        }


        @Override
        public Long move(byte[] key, int dbIndex) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.move(key, dbIndex);
            }
        }

        @Override
        public byte[] objectEncoding(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.objectEncoding(key);
            }
        }

        @Override
        public Long objectIdletime(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.objectIdletime(key);
            }
        }

        @Override
        public Long objectRefcount(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.objectRefcount(key);
            }
        }

        @Override
        public Long persist(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.persist(key);
            }
        }

        @Override
        public Long pexpire(byte[] key, long milliseconds) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.pexpire(key, milliseconds);
            }
        }

        @Override
        public Long pexpireAt(byte[] key, long millisecondsTimestamp) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.pexpireAt(key, millisecondsTimestamp);
            }
        }

        @Override
        public Long pfadd(byte[] key, byte[]... elements) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.pfadd(key, elements);
            }
        }

        @Override
        public long pfcount(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.pfcount(key);
            }
        }


        @Deprecated
        @Override
        public ShardedJedisPipeline pipelined() {
            try(ShardedJedis jedis = source.getSource()) {
                //return jedis.pipelined();
                return null;
            }
        }

        @Override
        public void resetState() {
            try(ShardedJedis jedis = source.getSource()) {
                jedis.resetState();
            }
        }


        @Override
        public byte[] rpop(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.rpop(key);
            }
        }


        @Override
        public Long rpush(byte[] key, byte[]... strings) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.rpush(key, strings);
            }
        }

        @Override
        public Long rpushx(byte[] key, byte[]... string) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.rpushx(key, string);
            }
        }

        @Override
        public Long sadd(byte[] key, byte[]... members) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.sadd(key, members);
            }
        }


        @Override
        public Long scard(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.scard(key);
            }
        }


        @Override
        public String set(byte[] key, byte[] value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.set(key, value);
            }
        }

        @Override
        public String set(byte[] key, byte[] value, byte[] nxxx, byte[] expx, long time) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.set(key, value, nxxx, expx, time);
            }}

        @Override
        public Boolean setbit(byte[] key, long offset, boolean value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.setbit(key, offset, value);
            }
        }

        @Override
        public Boolean setbit(byte[] key, long offset, byte[] value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.setbit(key, offset, value);
            }
        }

        @Override
        public String setex(byte[] key, int seconds, byte[] value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.setex(key, seconds, value);
            }
        }

        @Override
        public Long setnx(byte[] key, byte[] value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.setnx(key, value);
            }
        }

        @Override
        public Long setrange(byte[] key, long offset, byte[] value) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.setrange(key, offset, value);
            }
        }


        @Override
        public Boolean sismember(byte[] key, byte[] member) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.sismember(key, member);
            }
        }


        @Override
        public Set<byte[]> smembers(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.smembers(key);
            }
        }


        @Override
        public List<byte[]> sort(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.sort(key);
            }
        }

        @Override
        public List<byte[]> sort(byte[] key, SortingParams sortingParameters) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.sort(key, sortingParameters);
            }
        }

        @Override
        public byte[] spop(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.spop(key);
            }
        }

        @Override
        public Set<byte[]> spop(byte[] key, long count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.spop(key, count);
            }
        }

        @Override
        public byte[] srandmember(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.srandmember(key);
            }
        }

        @Override
        public List<byte[]> srandmember(byte[] key, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.srandmember(key, count);
            }
        }

        @Override
        public Long srem(byte[] key, byte[]... member) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.srem(key, member);
            }
        }


        @Override
        public Long strlen(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.strlen(key);
            }
        }

        @Override
        public byte[] substr(byte[] key, int start, int end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.substr(key, start, end);
            }
        }


        @Override
        public Long ttl(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.ttl(key);
            }
        }

        @Override
        public String type(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.type(key);
            }
        }

        @Override
        public Long zadd(byte[] key, double score, byte[] member) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zadd(key, score, member);
            }
        }

        @Override
        public Long zadd(byte[] key, Map<byte[], Double> scoreMembers) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zadd(key, scoreMembers);
            }
        }

        @Override
        public Long zcard(byte[] key) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zcard(key);
            }
        }

        @Override
        public Long zcount(byte[] key, byte[] min, byte[] max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zcount(key, min, max);
            }
        }

        @Override
        public Long zcount(byte[] key, double min, double max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zcount(key, min, max);
            }
        }

        @Override
        public Double zincrby(byte[] key, double score, byte[] member) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zincrby(key, score, member);
            }
        }

        @Override
        public Long zlexcount(byte[] key, byte[] min, byte[] max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zlexcount(key, min, max);
            }
        }

        @Override
        public Set<byte[]> zrange(byte[] key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrange(key, start, end);
            }
        }

        @Override
        public Set<byte[]> zrangeByLex(byte[] key, byte[] min, byte[] max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByLex(key, min, max);
            }
        }

        @Override
        public Set<byte[]> zrangeByLex(byte[] key, byte[] min, byte[] max, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByLex(key, min, max, offset, count);
            }
        }

        @Override
        public Set<byte[]> zrangeByScore(byte[] key, byte[] min, byte[] max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScore(key, min, max);
            }
        }

        @Override
        public Set<byte[]> zrangeByScore(byte[] key, byte[] min, byte[] max, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScore(key, min, max, offset, count);
            }
        }

        @Override
        public Set<byte[]> zrangeByScore(byte[] key, double min, double max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScore(key, min, max);
            }
        }

        @Override
        public Set<byte[]> zrangeByScore(byte[] key, double min, double max, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScore(key, min, max, offset, count);
            }
        }

        @Override
        public Set<Tuple> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScoreWithScores(key, min, max);
            }
        }

        @Override
        public Set<Tuple> zrangeByScoreWithScores(byte[] key, byte[] min, byte[] max, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScoreWithScores(key, min, max, offset, count);
            }
        }

        @Override
        public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScoreWithScores(key, min, max);
            }
        }

        @Override
        public Set<Tuple> zrangeByScoreWithScores(byte[] key, double min, double max, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeByScoreWithScores(key, min, max, offset, count);
            }
        }

        @Override
        public Set<Tuple> zrangeWithScores(byte[] key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrangeWithScores(key, start, end);
            }
        }

        @Override
        public Long zrank(byte[] key, byte[] member) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrank(key, member);
            }
        }

        @Override
        public Long zrem(byte[] key, byte[]... members) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrem(key, members);
            }
        }

        @Override
        public Long zremrangeByLex(byte[] key, byte[] min, byte[] max) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zremrangeByLex(key, min, max);
            }
        }

        @Override
        public Long zremrangeByRank(byte[] key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zremrangeByRank(key, start, end);
            }
        }

        @Override
        public Long zremrangeByScore(byte[] key, byte[] start, byte[] end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zremrangeByScore(key, start, end);
            }
        }

        @Override
        public Long zremrangeByScore(byte[] key, double start, double end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zremrangeByScore(key, start, end);
            }
        }

        @Override
        public Set<byte[]> zrevrange(byte[] key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrange(key, start, end);
            }
        }

        @Override
        public Set<byte[]> zrevrangeByLex(byte[] key, byte[] max, byte[] min) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByLex(key, max, min);
            }
        }

        @Override
        public Set<byte[]> zrevrangeByLex(byte[] key, byte[] max, byte[] min, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByLex(key, max, min, offset, count);
            }
        }

        @Override
        public Set<byte[]> zrevrangeByScore(byte[] key, byte[] max, byte[] min) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScore(key, max, min);
            }
        }

        @Override
        public Set<byte[]> zrevrangeByScore(byte[] key, byte[] max, byte[] min, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScore(key, max, min, offset, count);
            }
        }

        @Override
        public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScore(key, max, min);
            }
        }

        @Override
        public Set<byte[]> zrevrangeByScore(byte[] key, double max, double min, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScore(key, max, min, offset, count);
            }
        }

        @Override
        public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScoreWithScores(key, max, min);
            }
        }

        @Override
        public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, byte[] max, byte[] min, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScoreWithScores(key, max, min, offset, count);
            }
        }

        @Override
        public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScoreWithScores(key, max, min);
            }
        }

        @Override
        public Set<Tuple> zrevrangeByScoreWithScores(byte[] key, double max, double min, int offset, int count) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeByScoreWithScores(key, max, min, offset, count);
            }
        }

        @Override
        public Set<Tuple> zrevrangeWithScores(byte[] key, long start, long end) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrangeWithScores(key, start, end);
            }
        }

        @Override
        public Long zrevrank(byte[] key, byte[] member) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zrevrank(key, member);
            }
        }

        @Override
        public Double zscore(byte[] key, byte[] member) {
            try(ShardedJedis jedis = source.getSource()) {
                return jedis.zscore(key, member);
            }
        }
    }
}
